package com.yangsir.mysite.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yangsir.mysite.Dto.TagDto;
import com.yangsir.mysite.common.R;
import com.yangsir.mysite.mapper.TagMapper;
import com.yangsir.mysite.pojo.Tag;
import com.yangsir.mysite.service.TagService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author yf
* @description 针对表【tag(标签)】的数据库操作Service实现
* @createDate 2024-06-22 16:55:16
*/
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag>
    implements TagService {
    @Resource
    private TagMapper tagMapper;


    /**
     * 查询所有标签
     * @param type
     * @return
     */
    @Override
    public R<List<Tag>> quaryAllTags(Integer type) {
        LambdaQueryWrapper<Tag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Tag::getType, type);
        List<Tag> tags = tagMapper.selectList(queryWrapper);
        List<TagDto> tagsDto = new ArrayList<>();
        BeanUtils.copyProperties(tags, tagsDto);
        return R.success(tags, "查询成功");
    }
}




